#include "UserSelectionMenu.h"
#include "PrintUtilities.h"
#include "UserManager.h"
#include "Team.h"
#include "ServiceProvider.h"
#include "MenuManager.h"
#include "User.h"
#include "StringUtilities.h"

UserSelectionMenu::UserSelectionMenu(MenuManager* const i_menuManager)
	: Menu(i_menuManager)
	, m_userSelected(-1)
	, m_next(0)
{
}

void UserSelectionMenu::Draw() const
{
	STD::cout << Print::Title("PLAYER SELECTION MENU'");

	STD::cout << STD::endl << m_sentence << STD::endl << STD::endl;

	const UsersList& users = GetSP()->GetUserMgr().GetUserList();

	for (int i = 0; i < static_cast<int>(users.size()); ++i)
		STD::cout	<< i+1 << ") user: " << users.at(i)->m_name
					<< "  -  " << users.at(i)->m_team->GetName()
					<< STD::endl;
	if (users.empty())
	{
		STD::cout	<< " No players available!\n\n"
					<< Print::Options("0) Return to previous menu'");
	}
	else
	{
		STD::cout	<< "\n"
					<< Print::Options(	"num) select player\n\n"
										"0)   Return to previous menu'");
	}
	STD::cout << "Selection: ";
}

bool UserSelectionMenu::Input(const STL::string& i_input)
{
	bool goodInput = true;

	int res = Utilities::StringToInt(i_input);

	if (res < 0 || res > static_cast<int>(GetSP()->GetUserMgr().GetUserList().size()))
		return false;

	m_userSelected = res-1;

	if(res == 0)
		GetMM()->PopMenu();
	else
		GetMM()->SetMenu(m_next);

	return goodInput;
}

void UserSelectionMenu::SetNextMenu(Menu* i_next)
{
	m_next = i_next;
}
